package com.lzy.shops.utils.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Aspect
@Component
public class WebLogAcpect {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Around("execution(* com.lzy.shops.controller.backstage.*.*(..))")
    public Object roundAsp(ProceedingJoinPoint pj) {
        String methodName = pj.getSignature().getName();
        String className = pj.getTarget().getClass().getName();
        Object proceed = null;
        try {
            Object[] args = pj.getArgs();
            logger.info("管理员操作了"+className+"的"+methodName+"方法");
            proceed = pj.proceed(args);
        } catch (Throwable throwable) {
            logger.info("管理员操作了"+className+"的"+methodName+"方法，出现了异常"+throwable.getMessage());
            throwable.printStackTrace();
        }
        return proceed;
    }
}
